#include "junix.h"
using namespace std;

struct A
{
	A(){}

	virtual A* clone()=0;
};

struct B
:public A
{
	int i;
	B(int ii=0):i(ii){}
	A* clone()
	{
		return new B(*this);
	}
};

struct C
:public A
{
	int c;
	C(int cc=0):c(cc){}
	A* clone()
	{
		return new C(*this);
	}
};

int main(int argc, char **argv)
{
	A* pa = new B(1234);
	std::cout<<typeid(*pa).name()<<endl;
	A* pa2 = pa->clone();
	std::cout<<typeid(*pa2).name()<<endl;

	A* pa3 = new C(8888);
	std::cout<<typeid(pa3).name()<<std::endl;
	std::cout<<typeid(*pa3).name()<<std::endl;

	pa = pa3->clone();
	std::cout<< dynamic_cast<C*>(pa)->c<<endl;
}
